package high.concurent.controller;


import high.concurent.request.UserLoginRequest;
import high.concurent.request.UserRegistryRequest;
import high.concurent.service.UserService;
import high.concurrent.enums.BizCodeEnum;
import high.concurrent.utils.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 黄保泽
 * @since 2021-07-14
 */
@RestController
@RequestMapping("/api/user/v1")
@Api(tags = "用户模块")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户头像上传
     * @param file
     * @return
     */
    @ApiOperation("用户头像上传")
    @PostMapping(value = "uploadUserImg")
    public JsonData uploadUserImg(@RequestPart("file")MultipartFile file){
        String imagePath = userService.uploadUserImg(file);
        return imagePath == null?JsonData.buildResult(BizCodeEnum.FILE_UPLOAD_USER_IMG_FAIL):JsonData.buildSuccess(imagePath);
    }


    /**
     * 用户注册
     * @param userRegistryRequest
     * @return
     */
    @ApiOperation("用户注册")
    @PostMapping(value = "registry")
    public JsonData registry(@ApiParam("用户信息") @RequestBody UserRegistryRequest userRegistryRequest){

        JsonData jsonData = userService.registry(userRegistryRequest);
        return jsonData;
    }


    /**
     * 用户登录
     * @param userLoginRequest
     * @return
     */
    @ApiOperation("用户登录")
    @PostMapping(value = "login")
    public JsonData login(@ApiParam("用户信息") @RequestBody UserLoginRequest userLoginRequest){

        JsonData jsonData = userService.login(userLoginRequest);
        return jsonData;
    }

    /**
     * 查询用户详情
     * @return
     */
    @ApiOperation("查询用户详情")
    @GetMapping(value = "getUserDetail")
    public JsonData getUserDetail(){

        JsonData jsonData = userService.getUserDetail();
        return jsonData;
    }
}

